//
//  PushActivityView.m
//  YIJU2.0-HD
//
//  Created by 张金国 on 16/5/16.
//  Copyright © 2016年 张金国. All rights reserved.
//

#import "ZHBaseView.h"
#import "ZRButton.h"
#import "ImageLable.h"
#import "Masonry.h"
#import "Macro.h"

#define currentLineColor [UIColor colorWithWhite:0.872 alpha:1.0]//分割线颜色
#define currentBtnColor  [UIColor colorWithRed:0.8941 green:0.902 blue:0.9412 alpha:1.0]//button颜色
#define currentBtnTitleColor [UIColor colorWithWhite:0.3882 alpha:1.0]//button的title颜色
#define currentBtnBorderColor [UIColor colorWithWhite:0.8355 alpha:1.0]//button的边框颜色

@interface ZHBaseView ()

@property (nonatomic ,strong)ImageLable  *imageLable;

@property (nonatomic ,strong)ZRButton    *zRButton;

@property (nonatomic ,strong)UIView      *viewline;

@end

@implementation ZHBaseView

#pragma mark - init

- (instancetype)init
{
    if (self == [super init]) {
        self.backgroundColor = kUserInfoViewBackgroundColor;
        [self addSubview:self.imageLable];
        [self addSubview:self.zRButton];
        [self addSubview:self.viewline];
        [self setupContraints];
    }
    return self;
}

- (void)setupContraints {
  
    [self.imageLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self).offset(TenOffsetViewMargin);
        make.width.greaterThanOrEqualTo(TweentyOffsetViewMargin * 2);
        make.height.equalTo(@40);
    }];
    
    [self.zRButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-TenOffsetViewMargin);
        make.top.equalTo(self.mas_top).offset(TweentyOffsetViewMargin);
        make.width.equalTo(@53);
        make.height.equalTo(@25);
    }];
    
    [self.viewline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.zRButton.mas_bottom).offset(TenOffsetViewMargin);
        make.left.equalTo(self.imageLable.mas_left);
        make.right.equalTo(self.zRButton.mas_right);
        make.height.equalTo(@1);
    }];
    
}
#pragma mark - event respose
- (void)handleButtonEvent:(UIButton *)button {
    self.block();
}
#pragma mark - getter
- (UIView *)viewline {
    if (!_viewline) {
        _viewline = [[UIView alloc]init];
        _viewline.backgroundColor = currentLineColor;
    }
    return _viewline;
}

- (ZRButton *)zRButton {
    if (!_zRButton) {
        _zRButton = [ZRButton buttonWithBorderWidth:1.0f title:self.buttonText backgroundColor:currentBtnColor];
        [_zRButton setTitleColor:currentBtnTitleColor forState:UIControlStateNormal];
        _zRButton.layer.borderColor = currentBtnBorderColor.CGColor;
        [_zRButton addTarget:self action:@selector(handleButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _zRButton;
}

- (ImageLable *)imageLable {
    if (!_imageLable) {
        _imageLable = [[ImageLable alloc]initWithImage:self.imageName titleName:self.labeText];
    }
    return _imageLable;
}

#pragma mark - setters

- (void)setImageName:(NSString *)imageName {
    _imageName = imageName;
    UIImageView *imageView = [self.imageLable viewWithTag:100];
    imageView.image = [UIImage imageNamed:imageName];
}

- (void)setLabeText:(NSString *)labeText {
    _labeText = labeText;
    UILabel *label = [self.imageLable viewWithTag:101];
    label.text = labeText;
}

- (void)setButtonText:(NSString *)buttonText {
    _buttonText = buttonText;
    [self.zRButton setTitle:buttonText forState:UIControlStateNormal];

}
- (void)setIsShow:(BOOL)isShow {
    _isShow = isShow;
    if (isShow == NO) {
        self.zRButton.hidden = NO;
    }else {
        self.zRButton.hidden = YES;
    }

}


@end
